{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>消息通知</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="collapse" id="searchBox">
                        <div class="layui-form layui-form-item">
                            <div class="layui-input-inline layui-form">
                                <select name="type" lay-search="">
                                    <option  value="">不限消息类型</option>
                                    <option value="1">系统消息</option>
                                    <option value="2">个人消息</option>
                                </select>
                            </div>
                            <div class="layui-input-inline layui-form">
                                <select name="app" lay-search="">
                                    <option value="">不限接收端</option>
                                    <option value="1">用户端</option>
                                    <option value="2">商户端</option>
                                    <option value="3">业务端</option>
                                </select>
                            </div>
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="标题/内容"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group pull-left" >
                        <a href="javascript:;" onclick="tableReload()" class="btn btn-success" data-toggle="tooltip" title="" data-original-title="刷新表格" data-placement="auto">
                            <i class="fa fa-refresh"></i>
                        </a>
                        <a href="javascript:;" onclick="wk.href('{:url('noticeAdd')}')">
                            <button class="btn btn-primary" type="button">
                                <i class="fa fa-plus"></i> 添加消息
                            </button>
                        </a>
                    </div>
                    <div class="input-group pull-right" data-toggle="tooltip" title="" data-original-title="搜索">
                        <button class="btn btn-primary" data-toggle="collapse"
                                data-target="#searchBox" >
                            <i class="glyphicon glyphicon-search"></i>
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <ul onclick="view(this)" id="view_{{d.id}}">
                            <li><img data-original="{{d.portrait}}" src="{{d.portrait}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  /></li>
                        </ul>
                    </script>
                    <script type="text/html" id="appTpl">
                        {{# switch(d.n_app) { case 1: }}
                            用户端
                        {{# break; case 2 :}}
                            商户端
                        {{# break; default: }}
                            业务端
                        {{# break; } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.confirm('{{d.n_id}}','{:url('noticeDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o"></i></a>
                        {{# if(d.n_type == 1){ }}
                            {{#if(d.n_top == 1){ }}
                            <a href="javascript:;" onclick="topNotice('{{d.n_id}}',2)" class="btn btn-primary btn-xs m-r-xs" title="置顶"><i class="fa fa-thumbs-up"></i></a>
                            {{# }else{ }}
                            <a href="javascript:;" onclick="topNotice('{{d.n_id}}',1)" class="btn btn-default btn-xs m-r-xs" title="取消置顶"><i class="fa fa-thumbs-down"></i></a>
                            {{# } }}
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Notice/index")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'n_title', width: '', title: '消息标题', align: 'center'}
                , {field: 'n_content', width: '', title: '消息内容', align: 'center'}
                , {field: 'n_type', width: '', title: '消息类型', align: 'center', templet: "<div>{{ d.n_type == 1? '系统消息': '个人消息'}}</div>"}
                , {field: 'n_app', width: '', title: '接收端', align: 'center',templet:'#appTpl'}
                , {field: 'who', width: '', title: '接收人', align: 'center'}
                , {field: 'n_time', width: '', title: '添加时间', align: 'center'}
                , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
    });
    var topNotice = function(id,num){
        $.ajax({
            url:"{:url('topNotice')}",
            data:"id="+id+"&num="+num,
            dataType:'json',
            type:'post',
            success:function(res){
                if(res.code == 200){
                    if(num == 1){
                        layer.msg('取消置顶成功',{icon:1,time:1500,shade: 0.1},function(){
                            //重载当前页表格
                            $(".layui-laypage-btn").click();
                        });
                    }else{
                        layer.msg('置顶成功',{icon:1,time:1500,shade: 0.1},function(){
                            //重载当前页表格
                            $(".layui-laypage-btn").click();
                        });
                    }
                }else{
                    if(num == 1){
                        wk.success('取消置顶失败')
                    }else{
                        wk.success('置顶失败')
                    }
                }
            }
        })
    }
</script>
</body>
</html>